#pragma once

#include <algorithm/analytical_model/algorithm/cuda/inter_op/Data.h>

#include <cmath>

namespace solar::cuda
{
    template <typename T>
    inline __host__ __device__ auto absDivide(const T& denominator, const T& numerator) -> T
    {
        if (numerator <= inter_op::kEpsilon && numerator >= -inter_op::kEpsilon) [[unlikely]]
        {
            return T(INT_MAX);
        }
        return std::abs(denominator / numerator);
    }

    template <>
    inline __host__ __device__ auto absDivide(const float& denominator,
                                              const float& numerator) -> float
    {
        if (numerator <= float(inter_op::kEpsilon) && numerator >= float(-inter_op::kEpsilon))
            [[unlikely]]
        {
            return float(INT_MAX);
        }
#ifdef __CUDA_ARCH__
        return std::abs(fdividef(denominator, numerator));
#else
        return std::abs(denominator / numerator);
#endif
    }
} // namespace solar::cuda
